package org.util;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.bean.O2rankgame;

public class PlayerScroceImg {

	public static void setRGB(String patch, BufferedImage ImageNew, int x, int y,int r,int g, int b) {

		try {
			// 读取图片
			File fileBG = new File(patch);
			 BufferedImage ImageBG = ImageIO.read(fileBG);

			int BGwidth = ImageBG.getWidth();// 图片宽度
			int BGheight = ImageBG.getHeight();// 图片高度
			
			// 读取RGB
			int[] ImageArrayBG = new int[BGwidth * BGheight];
			ImageArrayBG = ImageBG.getRGB(0, 0, BGwidth, BGheight,
					ImageArrayBG, 0, BGwidth);
			
				
			
		//	ImageNew.setRGB(x, y, BGwidth, BGheight, ImageArrayBG, 0, BGwidth);// 设置RGB
		
			for(int i=0;i<BGwidth;i++){
			    for(int j=0;j<BGwidth;j++){
			    	int rgb=ImageBG.getRGB(i, j);
			    	
			        int R = (rgb & 0xff0000) >> 16;
			        int G = (rgb & 0xff00) >> 8;
			            int B = (rgb & 0xff);
			            rgb=((R*256)+G)*256+B;
			            if(R!=r&&G!=g&&B!=b){
			            	ImageNew.setRGB(i+x,j+y,rgb);
//			            	System.out.println(i+" "+j);
//			            	System.out.println(patch);
			            }		            
			    }
			   }
			
			
			
		} catch (Exception e) {
			System.out.println(e);
		}
	}

	public static void setFontRGB(String patch, BufferedImage ImageNew, int x, int y,int r,int g, int b,int fengex,int fengey) {

		try {
			// 读取图片
			File fileBG = new File(patch);
			 BufferedImage ImageBG = ImageIO.read(fileBG);
			 ImageBG= ImageBG.getSubimage(	fengex, fengey, 27, 21);
			 
			 
		

			int BGwidth = ImageBG.getWidth();// 图片宽度
			int BGheight = ImageBG.getHeight();// 图片高度
			
			// 读取RGB
			
			//他这张图的尺寸大小27*21
			int[] ImageArrayBG = new int[BGwidth * BGheight];
			ImageArrayBG = ImageBG.getRGB(0, 0, BGwidth, BGheight,
					ImageArrayBG, 0, BGwidth);
			
				
			
		//	ImageNew.setRGB(x, y, BGwidth, BGheight, ImageArrayBG, 0, BGwidth);// 设置RGB
		
			for(int i=0;i<BGwidth;i++){
			    for(int j=0;j<BGwidth;j++){
			    	if(j>=BGheight){
			    		break;
			    	}
			    	int rgb=ImageBG.getRGB(i, j);
			    
			        int R = (rgb & 0xff0000) >> 16;
			        int G = (rgb & 0xff00) >> 8;
			            int B = (rgb & 0xff);
			            rgb=((R*256)+G)*256+B;
			            if(R!=r&&G!=g&&B!=b){
			            	ImageNew.setRGB(i+x,j+y,rgb);
//			            	System.out.println(i+" "+j);
//			            	System.out.println(patch);
			            }		            
			    }
			   }
			
			
			
		} catch (Exception e) {
			System.out.println(e);
		}
	}

	public static void setFontRGB1(String patch, BufferedImage ImageNew, int x, int y,int r,int g, int b,int fengex,int fengey) {

		try {
			// 读取图片
			File fileBG = new File(patch);
			 BufferedImage ImageBG = ImageIO.read(fileBG);
			 ImageBG= ImageBG.getSubimage(	fengex, fengey, 27, 21);
			 
			 
		

			int BGwidth = ImageBG.getWidth();// 图片宽度
			int BGheight = ImageBG.getHeight();// 图片高度
			
			// 读取RGB
			
			//他这张图的尺寸大小27*21
			int[] ImageArrayBG = new int[BGwidth * BGheight];
			ImageArrayBG = ImageBG.getRGB(0, 0, BGwidth, BGheight,
					ImageArrayBG, 0, BGwidth);
			
				
			
		//	ImageNew.setRGB(x, y, BGwidth, BGheight, ImageArrayBG, 0, BGwidth);// 设置RGB
		
			for(int i=0;i<BGwidth;i++){
			    for(int j=0;j<BGwidth;j++){
			    	if(j>=BGheight){
			    		break;
			    	}
			    	int rgb=ImageBG.getRGB(i, j);
			    
			        int R = (rgb & 0xff0000) >> 16;
			        int G = (rgb & 0xff00) >> 8;
			            int B = (rgb & 0xff);
			            rgb=((R*256)+G)*256+B;
			            if(R!=r&&G!=g&&B!=b){
			            	ImageNew.setRGB(i+x,j+y,rgb);
//			            	System.out.println(i+" "+j);
//			            	System.out.println(patch);
			            }		            
			    }
			   }
			
			
			
		} catch (Exception e) {
			System.out.println(e);
		}
	}
	
	
	public static void setBGRGB(String patch, BufferedImage ImageNew, int x, int y) {

		try {
			// 读取图片
			File fileBG = new File(patch);
			BufferedImage ImageBG = ImageIO.read(fileBG);
			

			int BGwidth = ImageBG.getWidth();// 图片宽度
			int BGheight = ImageBG.getHeight();// 图片高度

			// 读取RGB
			int[] ImageArrayBG = new int[BGwidth * BGheight];
			ImageArrayBG = ImageBG.getRGB(0, 0, BGwidth, BGheight,
					ImageArrayBG, 0, BGwidth);
			ImageNew.setRGB(x, y, BGwidth, BGheight, ImageArrayBG, 0, BGwidth);// 设置RGB

			
			
			
		} catch (Exception e) {
			System.out.println(e);
		}
	}

	
	
	public static void setFont(String context,BufferedImage ImageNew,int x,int y,Color c){
		 
		Graphics2D g = ImageNew.createGraphics();// 得到图形上下文
		  g.setColor(c); // 设置画笔颜色 Color.LIGHT_GRAY
		  g.setFont(new Font("宋体", Font.PLAIN, 12));//设置字体
		  g.drawString(context, x, y);
		  g.dispose();
		
	}

	
	
	
	public static void main(String[] args) {

		// 生成新图片
		BufferedImage ImageNew = new BufferedImage(800, 600,
				BufferedImage.TYPE_INT_RGB);

		  
		
		// 背景图
		setBGRGB("D:\\image\\BG.bmp", ImageNew, 0, 0);
		
		// combo按钮
		setRGB("D:\\image\\COMBO.png", ImageNew, 68, 149,0,0,0);// 连击按钮部分
		
		
	// 如果连击是个位数 例子取 一位数
	// setRGB("D:\\image\\COMBO4.png", ImageNew, 71, 195);
	
	// 如果连击是个位数 例子取 两位数
	// setRGB("D:\\image\\COMBO3.png", ImageNew, 96, 195);
	// setRGB("D:\\image\\COMBO8.png", ImageNew, 46, 195);
	
	// 如果连击是个位数 例子取 三位数
	// setRGB("D:\\image\\COMBO1.png", ImageNew, 23, 195);
	// setRGB("D:\\image\\COMBO7.png", ImageNew, 73, 195);
	// setRGB("D:\\image\\COMBO8.png", ImageNew, 123, 195);
	
	// 如果连击是个位数 例子取 四位数
	setRGB("D:\\image\\COMBO1.png", ImageNew, -36, 172,0,0,0);
	setRGB("D:\\image\\COMBO1.png", ImageNew, 8, 172,0,0,0);
	setRGB("D:\\image\\COMBO1.png", ImageNew, 52, 172,0,0,0);
	setRGB("D:\\image\\COMBO1.png", ImageNew, 96, 172,0,0,0);

	//分数0
	setFontRGB("D:\\image\\font.png", ImageNew, 170, 565,255,82,255,124,0);
	
	
	
		
	
	//字体设置
	   setFont("52", ImageNew, 401, 162, Color.WHITE);		//等级
	  setFont("sixgod", ImageNew, 416, 162	, Color.YELLOW);	//玩家名
	  setFont("LZSB", ImageNew, 445, 550	, Color.WHITE);//歌曲名

	  
		// 生成文件
		File outFile = new File("d:\\image\\out.jpg");
		try {
			ImageIO.write(ImageNew, "jpg", outFile);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}// 写图片

	}
}

